package com.qz.mos.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

@Slf4j
@Component
@Profile( "cachemos" )
public class NettyMosApplicationRunner implements ApplicationRunner {


    @Autowired(required = false)
    private NettyReactiveWebServerFactory nettyWebServer;


    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {

        this.showUrl();
        log.info("\n====================================================\n" +
                "欢迎访问离线数据平台V1.0启动完成" +
                "\n====================================================\n");
    }

    private void showUrl() throws Exception{
        String host = InetAddress.getLocalHost().getHostAddress();
        int port = nettyWebServer.getPort();
        String contextPath = "";
        String protocol = nettyWebServer.getSsl() != null ? "https://" : "http://";
        String address = protocol + host + ":" + port + contextPath+"/";
        log.info("欢迎访问:{}", address);
        log.info("数据库后台:{}", address + "h2");
        log.info("\n" +
                "欢迎访问离线数据平台" +
                "\n");


    }


}
